//
// Created by zing on 3/31/2020.
//


#include <fcntl.h>           /* Definition of AT_* constants */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    char *filename = "text.txt";
    int fd = open(filename, O_RDONLY);
    if (fd == -1) {
        printf("文件不存在\n");
        fd = creat(filename, 0777);
        if (fd == -1) {
            perror("create file");
            return EXIT_FAILURE;
        }
        printf("创建文件\n");
    }
    filename = "aaa";
    int i = access(filename, W_OK);
    printf("W_OK %d\n", i);
    i = access(filename, R_OK);
    printf("R_OK %d\n", i);
    i = access(filename, X_OK);
    printf("X_OK %d\n", i);
    i = access(filename, F_OK);
    printf("F_OK %d\n", i);
    if (i == -1) {
        perror("access");
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}